<?php
namespace App\Http\Controllers\ApiWx\Mys;

use App\DBs\UserDB;
use Illuminate\Http\Request;

class UserController extends BaseController
{
    //视频

    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new UserDB();
    }

    /**
     * 一个
     */
    public function getOne(Request $request)
    {
        $wx = $request->post('wx','');
        $resDb = $this->db->getOneByWx($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }

    /**
     * 设置昵称
     */
    public function setUname(Request $request)
    {
        $wx = $request->post('wx','');
        $uname = $request->post('uname','');
        $resDb = $this->db->getOneByWx($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $resDb2 = $this->db->setUname($wx,$uname);
        if ($resDb2['code']!=0) {
            return $this->toWxJson(-3);
        }
        return $this->toWxJson(0);
    }

    /**
     * 申请果农
     */
    public function setGuoApply(Request $request)
    {
        $wx = $request->post('wx','');
        $resDb = $this->db->getOneByWx($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data']; $isguo = $items['isguo'];
        if ($isguo==1) {
            return array('code'=>'-4','msg'=>'申请中');
        } else if ($isguo==2) {
            return array('code'=>'-4','msg'=>'已拒绝');
//        } else if ($isguo==3) {
//            return array('code'=>'-4','msg'=>'已通过');
//        } else {
        }
        $resDb2 = $this->db->setGuoApply($wx);
        if ($resDb2['code']!=0) {
            return $this->toWxJson(-3);
        }
        $resDb = $this->db->getOneByWx($wx);
        $items = [
            'isguo'=>$resDb['data']['isguo'],
            'isGuoName'=>$resDb['data']['isGuoName'],
        ];
        return $this->toWxJson(0,$items);
    }

    /**
     * 申请商家
     */
    public function setShopApply(Request $request)
    {
        $wx = $request->post('wx','');
        $resDb = $this->db->getOneByWx($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data']; $isshop = $items['isshop'];
        if ($isshop==1) {
            return array('code'=>'-4','msg'=>'申请中');
        } else if ($isshop==2) {
            return array('code'=>'-4','msg'=>'已拒绝');
//        } else if ($isshop==3) {
//            return array('code'=>'-4','msg'=>'已通过');
//        } else {
        }
        $resDb2 = $this->db->setShopApply($wx);
        if ($resDb2['code']!=0) {
            return $this->toWxJson(-3);
        }
        $resDb = $this->db->getOneByWx($wx);
        $items = [
            'isshop'=>$resDb['data']['isshop'],
            'isShopName'=>$resDb['data']['isShopName'],
        ];
        return $this->toWxJson(0,$items);
    }
}